/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  XESReadServiceImpl.java                                      
 *  File Contents Outline :  XES读取服务
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package cn.edu.thu.log.web.service.impl;

import cn.edu.thu.log.web.service.XESReadService;
import cn.edu.thu.log.xes.XESFileReader;
import cn.edu.thu.log.xes.XESRandomReader;
import cn.edu.thu.log.xes.XESReaderInterface;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.deckfour.xes.model.XLog;
import storage.dbobject.DbXES;

public class XESReadServiceImpl implements XESReadService {

    public XESReaderInterface xesReader;
    boolean random;
    String name;
    private static XESReadService singleton = null;

    public synchronized static XESReadService instance() {
        if (singleton == null) {
            singleton = new XESReadServiceImpl();
        }
        return singleton;
    }
    private XESReadServiceImpl() {
            xesReader = new XESFileReader();
    }
    
  @Override
    public void setName(String name) {
       this.name = name;   
       //   xesReader.setUpXESPara(name);
    }
    @Override
    public void setRandom(boolean random) {
        this.random = random;
        if (random) {
            xesReader = new XESRandomReader();
            xesReader.setUpXESPara(name);
        } else {
            xesReader = new XESFileReader();
            xesReader.setUpXESPara(name);
        }
    }

    @Override
    public void setProportion(double proportion) {
        xesReader.setUpRandomProportion(proportion);
    }
    @Override
    public ArrayList<Float> gerRandomList() {
        return xesReader.gerRandomList();
    }

    @Override
    public boolean hasNext() {
        return xesReader.hadNext();

    }

    @Override
    public XLog next() {
        XLog log = null;
        try {
            log = xesReader.Next();
        } catch (Exception e) {
            Logger.getLogger(XESReadServiceImpl.class.getName()).log(Level.SEVERE, null, e);
        }
        return log;
    }
     @Override
    public DbXES nextXES() {
        DbXES xes = null;
        try {
            xes = xesReader.NextXES();
        } catch (Exception e) {
            Logger.getLogger(XESReadServiceImpl.class.getName()).log(Level.SEVERE, null, e);
        }
        return xes;
    }


}
